<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="${ctx}/static/bootstrap-3.3.4-dist/css/bootstrap.min.css">
<link rel="stylesheet" href="${ctx}/static/bootstrap-table-1.7.0/src/bootstrap-table.css">
<script type="text/javascript" src="${ctx}/static/bootstrap-3.3.4-dist/js/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="${ctx}/static/bootstrap-3.3.4-dist/js/bootstrap.js"></script>
<script type="text/javascript" src="${ctx}/static/bootstrap-table-1.7.0/src/bootstrap-table.min.js"></script>
<script type="text/javascript" src="${ctx}/static/bootstrap-table-1.7.0/src/locale/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript">
	var i = 6;
	$(function() {
		var url = location.search; //获取url中"?"符后的字串 
		if (url.indexOf("?") != -1) {
			var str = url.substr(1);
			strs = str.split("&");
			var appid = "";
			var code = "";
			var state = "";
			for (var i = 0; i < strs.length; i++) {
				if (strs[i].split("=")[0] == "appid") {
					appid = strs[i].split("=")[1];
				} else if (strs[i].split("=")[0] == "code") {
					code = strs[i].split("=")[1];
				} else if (strs[i].split("=")[0] == "state") {
					state = strs[i].split("=")[1];
				}
			}
			$.post("${ctx}/wxWeb/wxWebBasic/checkUser", {
				appid : appid,
				code : code,
				state : state
			}, function(data) {
				if (data.success) {
					setTimeout(function() {
						//WeixinJSBridge.call("closeWindow");
						window.open(data.obj.toString());
					}, 1500);
				} else {
					$("#msg").text(data.msg);
					$("#jumpUrl").val(data.obj.toString());
					$("#msgDialog").modal("show");
					/* alert(data.msg); */
					if (data.msg != null) {
						setInterval(fn_showTime, 1000);
					}
				}
			}, "json");
		}
		$("#close").click(function() {
			WeixinJSBridge.call("closeWindow");
		});
		$("#submit").click(function() {
			$("#msgDialog").modal("hide");
			window.open($("#jumpUrl").val());
		});
	});
	function fn_showTime() {
		i--;
		$("#timeshow").text(i + "秒后自动跳转!");
		if (i == 0) {
			window.open($("#jumpUrl").val());
		}
	}
</script>
</head>

<body>
	<div id="msgDialog" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
		aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-body">
					<p id="msg"></p>
					<p id="timeshow"></p>
					<input type="hidden" id="jumpUrl" />
				</div>
				<div class="modal-footer">
					<button id="submit" type="button" class="btn btn-primary">确定</button>
					<button id="close" type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
</body>
</html>
